<?php
class Database {
	var $_connection = "";
	var $_db = "";
	var $_query = "";
	
	function Database() {
		$db['default']['hostname'] = "localhost";
		$db['default']['username'] = 'bookabusesys';
		$db['default']['password'] = "1q2w3e4r5t";
		$db['default']['database'] = "bookabus_esys";
		
		$active_group = 'default';
		
		$this->_connection = mysql_connect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']) or die ("Error: could not connect to database");
		$this->_db = mysql_select_db($db[$active_group]['database']);
	}
	
	function close() {
		mysql_close($this->_connection);
	}
	
	function runSQL($rsql) {
		$this->_query = mysql_query($rsql, $this->_connection) or die (mysql_error() . "<br />". $rsql);
		return $this->_query;
	}
	
	function loadObject($query = false) {
		if ($query) {
			return mysql_fetch_object($query);
		} else {
			return mysql_fetch_object($this->_query);
		}
	}
	
	function loadObjectList($query = false) {
		$return = array();
		
		if ($query) {
			while ($row = mysql_fetch_object($query)) {
				$return[] = $row;
			}
		} else {
			while ($row = mysql_fetch_object($this->_query)) {
				$return[] = $row;
			}
		}
		
		return $return;
	}
}

$db = new Database();
?>